<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: AdminFieldsController.php 2010-08-31 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Page_AdminFieldsController extends Fields_Controller_AdminAbstract
{
	protected $_moduleName = 'Page';
	
  protected $_fieldType = 'page';
  
  protected $_requireProfileType = true;
  
  protected $_fieldTypeInfo = array();
  
	public function init()
  {
  	$this->view->option_id = $option_id = $this->_getParam('option_id');
  	
    $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
      ->getNavigation('page_admin_main', array(), 'page_admin_main_fields');
      
    parent::init();
  }
  
  public function indexAction()
  {
    parent::indexAction();
		$this->view->option_id = $this->_getParam('option_id', 1);
  }
  
	public function typeCreateAction()
  {
    parent::typeCreateAction();

		if (!$this->getRequest()->isPost()){
			$this->view->form->label->setLabel('Page Type Label');
			$this->view->form->submit->setLabel('Add Page Type');
		}
  }
  
  public function fieldCreateAction()
  {
  	parent::fieldCreateAction();
  	
  	if (!$this->getRequest()->isPost()){
  		$this->modifyFieldForm();
  	}
  }
  
	public function fieldEditAction()
  {
  	parent::fieldEditAction();
  	
  	if (!$this->getRequest()->isPost()){
  		$this->modifyFieldForm();
  	}
  }
  
  public function typeDeleteAction()
  {
    $option_id = $this->_getParam('option_id');
    if ($option_id == 1){
    	return ;
    }

    $table = Engine_Api::_()->getDbTable('pages', 'page');
    $db = $table->getAdapter();
    $prefix = $table->getTablePrefix();
    
    $db->update($prefix.'page_fields_values', array('value' => 1), "value = $option_id AND field_id = 1");
    
    parent::typeDeleteAction();
  }
  
  protected function modifyFieldForm()
  {
  	$form = $this->view->form;
  	$form->getElement('search')->setmultiOptions(array('Hide on Browse Pages', 'Show on Browse Pages'));
  	$form->getElement('display')->setmultiOptions(array('Hide on Page Profile', 'Show on Page Profile'));
  	
  	$form->setTitle('Edit Page Field');
  	$form->getElement('type')->setLabel('Page Type');
  	$form->getElement('label')->setLabel('Field Label');
  	$options = $form->getElement('type')->getmultiOptions();
  	unset($options['Specific']);
  	$form->getElement('type')->setmultiOptions($options);
  	
    // Check license
	/* Nulled By Hazaraboy
    $hecoreApi = Engine_Api::_()->getApi('core', 'hecore');
    $product_result = $hecoreApi->checkProduct('pages');
    
    if (isset($product_result['result']) && !$product_result['result']) {
      $form->addError($product_result['message']);
      $this->view->headScript()->appendScript($product_result['script']);
    
      return;
    } */
  }
}